﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MyFleView.Core
{
    public class ListSupport:ArrayList
    {
        public ListSupport(ICollection c) 
        {
            AddAll(c);
        }

        /// <summary>
        /// Adds all the elements of the specified collection that are not present to the list.
        /// 添加指定集合中所有不存在于列表中的元素。
        /// </summary>
        /// <param name="c">将添加新元素的集合</param>
        /// <returns>R如果至少添加了一个元素则返回true，否则返回false</returns>
        public bool AddAll(System.Collections.ICollection c)
        {
            System.Collections.IEnumerator e = new System.Collections.ArrayList(c).GetEnumerator();
            bool added = false;

            while (e.MoveNext())
            {
                if (Add(e.Current))
                    added = true;
            }

            return added;
        }
        /// <summary>
        /// 向数组列表中添加一个尚未存在的新元素。
        /// </summary>		
        /// <param name="obj">要插入到数组列表中的元素.</param>
        /// <returns>如果插入了新元素则返回true，否则返回false。.</returns>
        new public virtual bool Add(object obj)
        {
            bool inserted;

            if ((inserted = Contains(obj)) == false)
            {
                base.Add(obj);
            }

            return !inserted;
        }
    }
}